package chat;

import gui.ChatVoxGui;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

import controle.SocketControlConstants;


public class ClientListener extends Thread implements SocketControlConstants
{ 

	private ServerSocket serverSocket;
	private int portaEntrada;
	private ChatVoxGui chatVoxGui;
	
	
	public ClientListener(int portaEntrada, ChatVoxGui chatVoxGui)
	{
		this.portaEntrada = portaEntrada;
		this.chatVoxGui = chatVoxGui;
	}
		
	public void run(){		
		
		try
		{
			this.serverSocket = new ServerSocket(this.portaEntrada);
			while(true)
			{	
				System.out.println("ClientListener -> Ouvindo na porta :" + this.portaEntrada);
				Socket client =  this.serverSocket.accept();
				ClientHandler clientHandler= new ClientHandler(client, this.chatVoxGui);
				clientHandler.start();
			}
		}	
		catch(IOException e){
			e.printStackTrace();
		}
	}
}
